
import {
    Alert,
    Button,
    StyleSheet,
    Text,
    TouchableOpacity,
    View,
    Image
  } from 'react-native';
  import React,{useCallback, useEffect, useState} from 'react'; 
  import {RNExOcr} from 'mp-native'

  
  export default function OrientationLockerExample() {
    const [imageUri, setImageUri] = useState<string>();

    useEffect(() => {
      // 开启方向变化的监听

    }, []);
  
    // 锁定上下的方向
    const IDCard = () => {
        RNExOcr.recognizeIDCard({"certificateType":4,"fileName":"Mmh4s4On","menuOptions":2,"timeout":"10"}).then((res) => {
            console.log('res', res);
            setImageUri(res.originalImg)
        }).catch((err: any) => { 
            console.log(`error:`,err)  
        });
    };
    const bankCard = () => {
      RNExOcr.recognizeBankCard({"certificateType":2,"fileName":"2FkGtB3t","timeout":"10"}).then((res) => {
          console.log('res', res);
          setImageUri(res.originalImg)
      }).catch((err: any) => { 
          console.log(`error:`,err)  
      });
  };
  

  
    return (
      <View >
        <Image style={{width: 200, height: 200}} source={{
          uri:imageUri,
        }} />
        <Button  title="扫描身份证"
          onPress={IDCard}
        />
        <View style={{height:10}}></View>
        <Button  title="扫描银行卡"
          onPress={bankCard}
        />
      </View>
    );
  }
  
  const styles = StyleSheet.create({
    container: {
      width: '100%',
       height: 200,
      justifyContent: 'flex-start',
      alignItems: 'center',
      backgroundColor: '#fff',
      marginTop: 20,
    },
  });
  
  